package com.draemoncode.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import org.apache.mina.core.session.IoSession;
import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;

import com.draemoncode.WeixinduboApplication;
import com.draemoncode.action.TingzhiXiaZhuAction;
import com.draemoncode.socket.MinaAcceptListener;

import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.JEditorPane;
import javax.swing.JTable;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import java.awt.Color;

public class SimpleApplication extends JFrame {

	private JPanel contentPane;
	private JTable table_1;
	private JTable table_2;
	private JButton button;
	private JScrollPane scrollPane_1;
	private JScrollPane scrollPane_2;
	private JTextField textField;
	private JButton btnNewButton;
	private JLabel lblNewLabel_1;
	private IoSession session;
	private JFrame view;
	
	
	public JFrame getView() {
		return view;
	}

	public void setView(JFrame view) {
		this.view = view;
	}

	public IoSession getSession() {
		return session;
	}

	public void setSession(IoSession session) {
		this.session = session;
	}

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		ConfigurableApplicationContext context = SpringApplication.run(WeixinduboApplication.class, args);
		try {
			BeautyEyeLNFHelper.launchBeautyEyeLNF();
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SimpleApplication frame = new SimpleApplication();
					Binding.initUI(frame);
					MinaAcceptListener minaAcceptListener = new MinaAcceptListener();
					minaAcceptListener.setView(frame);
					minaAcceptListener.init(7100);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SimpleApplication() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(10, 10, 1240, 750);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JEditorPane editorPane = new JEditorPane();
		editorPane.setBounds(10, 530, 1164, 121);
		contentPane.add(editorPane);
		
		scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(10, 101, 703, 419);
		contentPane.add(scrollPane_1);
		
		table_1 = new JTable();
		scrollPane_1.setViewportView(table_1);
		
		scrollPane_2 = new JScrollPane();
		scrollPane_2.setBounds(723, 101, 451, 419);
		contentPane.add(scrollPane_2);
		
		table_2 = new JTable();
		scrollPane_2.setViewportView(table_2);
		
		btnNewButton = new JButton("新开一局");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnNewButton.setBounds(10, 6, 275, 85);
		contentPane.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("停止下注");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new TingzhiXiaZhuAction().exec(session, getView());
			}
		});
		btnNewButton_1.setBounds(295, 6, 123, 45);
		contentPane.add(btnNewButton_1);
		
		button = new JButton("结算");
		button.setBounds(295, 54, 123, 37);
		contentPane.add(button);
		
		JLabel lblNewLabel = new JLabel("标庄：");
		lblNewLabel.setForeground(new Color(102, 0, 204));
		lblNewLabel.setFont(new Font("宋体", Font.BOLD, 24));
		lblNewLabel.setBounds(528, 6, 90, 41);
		contentPane.add(lblNewLabel);
		
		textField = new JTextField();
		lblNewLabel.setLabelFor(textField);
		textField.setHorizontalAlignment(SwingConstants.RIGHT);
		textField.setForeground(Color.RED);
		textField.setFont(new Font("宋体", Font.BOLD, 24));
		textField.setText("3000.00");
		textField.setEditable(false);
		textField.setBounds(528, 54, 185, 37);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JPanel panel = new JPanel();
		panel.setBackground(Color.CYAN);
		panel.setBounds(428, 6, 90, 85);
		contentPane.add(panel);
		
		lblNewLabel_1 = new JLabel("魔影");
		lblNewLabel_1.setForeground(new Color(0, 0, 0));
		lblNewLabel_1.setFont(new Font("宋体", Font.BOLD, 24));
		lblNewLabel_1.setBounds(617, 6, 96, 41);
		contentPane.add(lblNewLabel_1);
	}
	public JTable getPodDetailTable() {
		return table_1;
	}
	public JTable getPodListTable() {
		return table_2;
	}
	public JButton getNewPod() {
		return btnNewButton;
	}
	public JLabel getZhuangNameLabel() {
		return lblNewLabel_1;
	}
	public JTextField getZhuangMoneyText() {
		return textField;
	}
}
